import Vue from 'vue';

export default class Tool {
  static getRoutes(_this, routesName) {
    if (!_this) {
      console.log('第一个参数需要提供vue的this指向！');
      return null;
    }
    const { routes } = _this.$router.options || null;
    if (!routesName) return routes;
    return routes.filter((item) => item.name === routesName)[0] || null;
  }

  static randomNum(minNum, maxNum) {
    switch (arguments.length) {
      case 1:
        return parseInt(Math.random() * minNum + 1, 10);
      case 2:
        return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
      default:
        return 0;
    }
  }

  // 将总秒数转为00:00的形式、
  static durationFormat(total) {
    return `${(`00${window.parseInt(total / 60)}`).slice(-2)}:${(`00${window.parseInt(total % 60)}`).slice(-2)}`;
  }
}
